package com.lepu.app.usercenter.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.app.utils.Setting;
import com.core.lib.application.BaseFragment;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.widget.MyDialog;
import com.lepu.app.usercenter.util.UserCenterUtil;
import com.lepu.pasm.R;

import org.json.JSONException;
import org.json.JSONObject;

public class FragmentPwdTell extends BaseFragment{

	private View mMainView = null;
	private boolean mInitDataSuccess = false;// 是否加载完数据

	@SuppressLint("InflateParams")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mMainView = LayoutInflater.from(getActivity()).inflate(
				R.layout.usercenter_forget_pwd_fragment_tell, null, false);
		init();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);

		ViewGroup p = (ViewGroup) mMainView.getParent();
		if (p != null) {
			p.removeAllViewsInLayout();
		}
		return mMainView;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

		mInitDataSuccess = false;
	}

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);

		if (isVisibleToUser) {
			if (!mInitDataSuccess) {
				// 第一次进入页面获取数据
				mInitDataSuccess = true;
			}
		}
	}

	/*
	 * 初始化ui控件，不要初始化数据！！！！
	 * 
	 * 初始化控件，需要用mMainView.findViewById 不能使用findViewById，否则程序会闪退的
	 */
	private void init() {
		Button telButton = (Button) mMainView
				.findViewById(R.id.telButton);
		telButton.setOnClickListener(mOnClickListener);

		telButton.setText(Setting.TELL_PHONE);
	}

	private void tell(final String phone) {
		if(TextUtils.isEmpty(phone)){
			return;
		}

		MyDialog myDialog = new MyDialog(getActivity());
		myDialog.setTitle("拨打电话").setMessage(phone).
				setNegativeButton(R.string.cancel, null).
				setPositiveButton(R.string.app_ok, new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						Uri uri = Uri.parse("tel:" + phone);
						Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, uri);
						startActivity(intentCallPhone);

					}
				}).create(null).show();
	}

	private View.OnClickListener mOnClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.telButton:
				tell(Setting.TELL_PHONE);
				break;

			default:
				break;
			}
		}
	};
}
